﻿using System;
using System.Collections.Generic;
using System.Text;
using AMStudio.Script;
using System.Windows.Forms;
using System.Collections;

namespace AMStudio.Common
{
    [Serializable()]
    public class ProductSettings:ICloneable
    {
        #region Station 1
        private int st1NestID = 1;

        public int St1NestID
        {
            get { return st1NestID; }
            set { st1NestID = value; }
        }

        private bool st1CheckHousingAssemblySN = false;

        public bool St1CheckHousingAssemblySN
        {
            get { return st1CheckHousingAssemblySN; }
            set { st1CheckHousingAssemblySN = value; }
        }

        private bool st1Connecter_PokaYoke = false;

        public bool St1Connecter_PokaYoke
        {
            get { return st1Connecter_PokaYoke; }
            set { st1Connecter_PokaYoke = value; }
        }

        private bool st1HousingCheckEnable = false;
        public bool St1HousingCheckEnable
        {
            get { return st1HousingCheckEnable; }
            set { st1HousingCheckEnable = value; }
        }
        private string st1HousingSNRequirement = string.Empty;
        public string St1HousingSNRequirement
        {
            get { return st1HousingSNRequirement; }
            set { st1HousingSNRequirement = value; }
        }

        private bool st1ConnectorCheckEnable = false;
        public bool St1ConnectorCheckEnable
        {
            get { return st1ConnectorCheckEnable; }
            set { st1ConnectorCheckEnable = value; }
        }
        private string st1ConnectorSNRequirement = string.Empty;
        public string St1ConnectorSNRequirement
        {
            get { return st1ConnectorSNRequirement; }
            set { st1ConnectorSNRequirement = value; }
        }

        private bool st1CameraEnable = false;

        public bool St1CameraEnable
        {
            get { return st1CameraEnable; }
            set { st1CameraEnable = value; }
        }
        private string st1CameraJob = string.Empty;

        public string St1CameraJob
        {
            get { return st1CameraJob; }
            set { st1CameraJob = value; }
        }

        private bool st1UseForntSensor = false;

        public bool St1UseForntSensor
        {
            get { return st1UseForntSensor; }
            set { st1UseForntSensor = value; }
        }

        private bool st1PressMode = true;

        public bool St1PressMode
        {
            get { return st1PressMode; }
            set { st1PressMode = value; }
        }

        #endregion

        #region Station 2

        private int st2ProgramID = 1;

        public int St2ProgramID
        {
            get { return st2ProgramID; }
            set { st2ProgramID = value; }
        }

        private int st2ToolingID = 1;

        public int St2ToolingID
        {
            get { return st2ToolingID; }
            set { st2ToolingID = value; }
        }
        
        #endregion

        #region Station 3

        private int st3LeftToolingID = 1;
        public int St3LeftToolingID
        {
            get { return st3LeftToolingID; }
            set { st3LeftToolingID = value; }
        }

        private int st3RightToolingID = 1;
        public int St3RightToolingID
        {
            get { return st3RightToolingID; }
            set { st3RightToolingID = value; }
        }

        private decimal st3ClampGrip;
        public decimal St3ClampGrip
        {
            get { return st3ClampGrip; }
            set { st3ClampGrip = value; }
        }

        private decimal st3ClampLoosen;
        public decimal St3ClampLoosen
        {
            get { return st3ClampLoosen; }
            set { st3ClampLoosen = value; }
        }

        private decimal st3GripX;
        public decimal St3GripX
        {
            get { return st3GripX; }
            set { st3GripX = value; }
        }

        private decimal st3GripY;
        public decimal St3GripY
        {
            get { return st3GripY; }
            set { st3GripY = value; }
        }

        private decimal st3GripZ;
        public decimal St3GripZ
        {
            get { return st3GripZ; }
            set { st3GripZ = value; }
        }

        private decimal st3LoosenX;
        public decimal St3LoosenX
        {
            get { return st3LoosenX; }
            set { st3LoosenX = value; }
        }

        private decimal st3LoosenY;
        public decimal St3LoosenY
        {
            get { return st3LoosenY; }
            set { st3LoosenY = value; }
        }

        private decimal st3LoosenZ;
        public decimal St3LoosenZ
        {
            get { return st3LoosenZ; }
            set { st3LoosenZ = value; }
        }

        private decimal st3HoverZ;
        public decimal St3HoverZ
        {
            get { return st3HoverZ; }
            set { st3HoverZ = value; }
        }

        #endregion

        #region Station 4
        private int st4ToolingID = 1;
        public int St4ToolingID
        {
            get { return st4ToolingID; }
            set { st4ToolingID = value; }
        }

        private int st4ProgramID = 1;

        public int St4ProgramID
        {
            get { return st4ProgramID; }
            set { st4ProgramID = value; }
        }     

        #endregion
        
        #region Station 5

        private bool st5Enable1 = false;

        public bool St5Enable1
        {
            get { return st5Enable1; }
            set { st5Enable1 = value; }
        }

        private bool st5Enable2 = false;

        public bool St5Enable2
        {
            get { return st5Enable2; }
            set { st5Enable2 = value; }
        }

        private bool st5Enable3 = false;

        public bool St5Enable3
        {
            get { return st5Enable3; }
            set { st5Enable3 = value; }
        }

        private bool st5Enable4 = false;

        public bool St5Enable4
        {
            get { return st5Enable4; }
            set { st5Enable4 = value; }
        }

        private bool st5Enable5 = false;

        public bool St5Enable5
        {
            get { return st5Enable5; }
            set { st5Enable5 = value; }
        }

        private string st5ProgramNO = "0";
        public string St5ProgramNO
        {
          get { return st5ProgramNO; }
          set { st5ProgramNO = value; }
        }

        private decimal st5X1;
        public decimal St5X1
        {
            get { return st5X1; }
            set { st5X1 = value; }
        }

        private decimal st5Y1;
        public decimal St5Y1
        {
            get { return st5Y1; }
            set { st5Y1 = value; }
        }

        private decimal st5Z1;
        public decimal St5Z1
        {
            get { return st5Z1; }
            set { st5Z1 = value; }
        }

        private decimal st5X2;
        public decimal St5X2
        {
            get { return st5X2; }
            set { st5X2 = value; }
        }

        private decimal st5Y2;
        public decimal St5Y2
        {
            get { return st5Y2; }
            set { st5Y2 = value; }
        }

        private decimal st5Z2;
        public decimal St5Z2
        {
            get { return st5Z2; }
            set { st5Z2 = value; }
        }

        private decimal st5X3;
        public decimal St5X3
        {
            get { return st5X3; }
            set { st5X3 = value; }
        }

        private decimal st5Y3;
        public decimal St5Y3
        {
            get { return st5Y3; }
            set { st5Y3 = value; }
        }

        private decimal st5Z3;
        public decimal St5Z3
        {
            get { return st5Z3; }
            set { st5Z3 = value; }
        }

        private decimal st5X4;
        public decimal St5X4
        {
            get { return st5X4; }
            set { st5X4 = value; }
        }

        private decimal st5Y4;
        public decimal St5Y4
        {
            get { return st5Y4; }
            set { st5Y4 = value; }
        }

        private decimal st5Z4;
        public decimal St5Z4
        {
            get { return st5Z4; }
            set { st5Z4 = value; }
        }

        private decimal st5X5;
        public decimal St5X5
        {
            get { return st5X5; }
            set { st5X5 = value; }
        }

        private decimal st5Y5;
        public decimal St5Y5
        {
            get { return st5Y5; }
            set { st5Y5 = value; }
        }

        private decimal st5Z5;
        public decimal St5Z5
        {
            get { return st5Z5; }
            set { st5Z5 = value; }
        }

        private bool st5ProductCheckEnable = false;

        public bool St5ProductCheckEnable
        {
            get { return st5ProductCheckEnable; }
            set { st5ProductCheckEnable = value; }
        }

        private string st5RightPartNO = "";

        public string St5RightPartNO
        {
            get { return st5RightPartNO; }
            set { st5RightPartNO = value; }
        }

        private string st5NegativePartNO = "";

        public string St5NegativePartNO
        {
            get { return st5NegativePartNO; }
            set { st5NegativePartNO = value; }
        }

        private string st5ProductCheckProgramNO = "0";

        public string St5ProductCheckProgramNO
        {
            get { return st5ProductCheckProgramNO; }
            set { st5ProductCheckProgramNO = value; }
        }

        #endregion

        #region Station 6

        private int st6PositionJobID = 1;
        public int St6PositionJobID
        {
            get { return st6PositionJobID; }
            set { st6PositionJobID = value; }
        }

        private int st6ECheckToolingID = 1;
        public int St6ECheckToolingID
        {
            get { return st6ECheckToolingID; }
            set { st6ECheckToolingID = value; }
        }

        private int st6LeftGripperToolingID = 1;
        public int St6LeftGripperToolingID
        {
            get { return st6LeftGripperToolingID; }
            set { st6LeftGripperToolingID = value; }
        }

        private int st6RightGripperToolingID = 1;
        public int St6RightGripperToolingID
        {
            get { return st6RightGripperToolingID; }
            set { st6RightGripperToolingID = value; }
        }

        private string st6CanDll = string.Empty;
        public string St6CanDll
        {
            get { return st6CanDll; }
            set { st6CanDll = value; }
        }

        private int st6DelayTime = 1;
        public int St6DelayTime
        {
            get { return st6DelayTime; }
            set { st6DelayTime = value; }
        }

        private int st6RetestTimes = 1;
        public int St6RetestTimes
        {
            get { return st6RetestTimes; }
            set { st6RetestTimes = value; }
        }

        #endregion

        private bool st8NeedDispatch = false;

        public bool St8NeedDispatch
        {
            get { return st8NeedDispatch; }
            set { st8NeedDispatch = value; }
        }

        private int st8DispathQuantity = 0;

        public int St8DispathQuantity
        {
            get { return st8DispathQuantity; }
            set { st8DispathQuantity = value; }
        }

        private string st8DispathPrinterFile = string.Empty;

        public string St8DispathPrinterFile
        {
            get { return st8DispathPrinterFile; }
            set { st8DispathPrinterFile = value; }
        }
        
        

        #region StationEnable
        private bool st1Enable = true;

        public bool St1Enable
        {
            get { return st1Enable; }
            set { st1Enable = value; }
        }
        private bool st2Enable = true;

        public bool St2Enable
        {
            get { return st2Enable; }
            set { st2Enable = value; }
        }
        private bool st3Enable = true;

        public bool St3Enable
        {
            get { return st3Enable; }
            set { st3Enable = value; }
        }
        private bool st4Enable = true;

        public bool St4Enable
        {
            get { return st4Enable; }
            set { st4Enable = value; }
        }
        private bool st5Enable = true;

        public bool St5Enable
        {
            get { return st5Enable; }
            set { st5Enable = value; }
        }
        private bool st6Enable = true;

        public bool St6Enable
        {
            get { return st6Enable; }
            set { st6Enable = value; }
        }

        #endregion

        #region "ProductBaseInformation"
        private string name = string.Empty;
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
        private string description = string.Empty;
        public string Description
        {
            get { return description; }
            set { description = value; }
        }
        private string comments = string.Empty;
        public string Comments
        {
            get { return comments; }
            set { comments = value; }
        }
        private string remark = string.Empty;
        public string Remark
        {
            get { return remark; }
            set { remark = value; }
        }
        private string testParameterInStation1 = string.Empty;
        public string TestParameterInStation1
        {
            get { return testParameterInStation1; }
            set { testParameterInStation1 = value; }
        }
        #endregion
        
        public object Clone()
        {
            ProductSettings p = new ProductSettings();
            p.name = this.name;

            return p;
        }

        public int[] St3SettingsToPLCWords()
        {
            int[] temp = new int[18];
            Int32 nOrignal = Int32.Parse(this.st3LoosenX.ToString());
            temp[0] = nOrignal & 0xffff;
            temp[1] = (nOrignal >> 16) & 0xffff;

            nOrignal = Int32.Parse(this.st3GripX.ToString());
            temp[2] = nOrignal & 0xffff;
            temp[3] = (nOrignal >> 16) & 0xffff;

            nOrignal = Int32.Parse(this.St3LoosenY.ToString());
            temp[4] = nOrignal & 0xffff;
            temp[5] = (nOrignal >> 16) & 0xffff;

            nOrignal = Int32.Parse(this.St3GripY.ToString());
            temp[6] = nOrignal & 0xffff;
            temp[7] = (nOrignal >> 16) & 0xffff;

            nOrignal = Int32.Parse(this.St3GripZ.ToString());
            temp[8] = nOrignal & 0xffff;
            temp[9] = (nOrignal >> 16) & 0xffff;

            nOrignal = Int32.Parse(this.St3LoosenZ.ToString());
            temp[10] = nOrignal & 0xffff;
            temp[11] = (nOrignal >> 16) & 0xffff;

            nOrignal = Int32.Parse(this.st3HoverZ.ToString());
            temp[12] = nOrignal & 0xffff;
            temp[13] = (nOrignal >> 16) & 0xffff;

            nOrignal = Int32.Parse(this.st3ClampGrip.ToString());
            temp[14] = nOrignal & 0xffff;
            temp[15] = (nOrignal >> 16) & 0xffff;

            nOrignal = Int32.Parse(this.St3ClampLoosen.ToString());
            temp[16] = nOrignal & 0xffff;
            temp[17] = (nOrignal >> 16) & 0xffff;
            return temp;
        }

         
        public int[] St5SettingsToPLCWords()
        {
            int[] temp = new int[30];
            Int32 nOrignal = Int32.Parse(this.st5X1.ToString());
            temp[0] = nOrignal & 0xffff;
            temp[1] = (nOrignal >> 16) & 0xffff;

            nOrignal = Int32.Parse(this.St5Y1.ToString());
            temp[2] = nOrignal & 0xffff;
            temp[3] = (nOrignal >> 16) & 0xffff;

            nOrignal = Int32.Parse(this.St5Z1.ToString());
            temp[4] = nOrignal & 0xffff;
            temp[5] = (nOrignal >> 16) & 0xffff;

            nOrignal = Int32.Parse(this.st5X2.ToString());
            temp[6] = nOrignal & 0xffff;
            temp[7] = (nOrignal >> 16) & 0xffff;

            nOrignal = Int32.Parse(this.St5Y2.ToString());
            temp[8] = nOrignal & 0xffff;
            temp[9] = (nOrignal >> 16) & 0xffff;

            nOrignal = Int32.Parse(this.St5Z2.ToString());
            temp[10] = nOrignal & 0xffff;
            temp[11] = (nOrignal >> 16) & 0xffff;

            nOrignal = Int32.Parse(this.st5X3.ToString());
            temp[12] = nOrignal & 0xffff;
            temp[13] = (nOrignal >> 16) & 0xffff;

            nOrignal = Int32.Parse(this.St5Y3.ToString());
            temp[14] = nOrignal & 0xffff;
            temp[15] = (nOrignal >> 16) & 0xffff;

            nOrignal = Int32.Parse(this.St5Z3.ToString());
            temp[16] = nOrignal & 0xffff;
            temp[17] = (nOrignal >> 16) & 0xffff;

            nOrignal = Int32.Parse(this.st5X4.ToString());
            temp[18] = nOrignal & 0xffff;
            temp[19] = (nOrignal >> 16) & 0xffff;

            nOrignal = Int32.Parse(this.St5Y4.ToString());
            temp[20] = nOrignal & 0xffff;
            temp[21] = (nOrignal >> 16) & 0xffff;

            nOrignal = Int32.Parse(this.St5Z4.ToString());
            temp[22] = nOrignal & 0xffff;
            temp[23] = (nOrignal >> 16) & 0xffff;

            nOrignal = Int32.Parse(this.st5X5.ToString());
            temp[24] = nOrignal & 0xffff;
            temp[25] = (nOrignal >> 16) & 0xffff;

            nOrignal = Int32.Parse(this.St5Y5.ToString());
            temp[26] = nOrignal & 0xffff;
            temp[27] = (nOrignal >> 16) & 0xffff;

            nOrignal = Int32.Parse(this.St5Z5.ToString());
            temp[28] = nOrignal & 0xffff;
            temp[29] = (nOrignal >> 16) & 0xffff;
            return temp;
        }
        
    }

    //[Serializable()]
    //public class StationSettings
    //{
    //    private string name = string.Empty;
    //    public string Name
    //    {
    //        get
    //        {
    //            return name;
    //        }
    //        set
    //        {
    //            name = value;
    //        }
    //    }

    //    private bool enabled = false;
    //    public bool Enable
    //    {
    //        get
    //        {
    //            return enabled;
    //        }
    //        set
    //        {
    //            enabled = value;
    //        }
    //    }
    //    private int programid = 0;
    //    public int ProgramId
    //    {
    //        get
    //        {
    //            return programid;
    //        }
    //        set
    //        {
    //            programid = value;
    //        }
    //    }

    //    private Hashtable settings = new Hashtable();
    //    public void AddSettings(string name, object value)
    //    {
    //        settings.Add(name, value);
    //    }
    //    public void AddSettings<T>(string name, T value)
    //    {
    //        settings.Add(name, value);
    //    }
    //    public object GetSettings(string name)
    //    {
    //        return settings[name];
    //    }

    //    public T GetSettings<T>(string name)
    //    {
    //        return (T)settings[name];
    //    }

    //    public void UpdateSettings(string name, object value)
    //    {
    //        if (settings.ContainsKey(name))
    //        {
    //            settings.Remove(name);
    //        }
    //        settings.Add(name, value);
    //    }

    //}
}
